CFLAGS += -m32 -march=i686
LDFLAGS += -m elf_i386

BOOT_SRCS = arch/x86/boot/boot.S
BOOT_OBJS = $(BOOT_SRCS:.S=.o)

CONSOLE_SRCS = arch/x86/boot/early_console.c
CONSOLE_OBJS = $(CONSOLE_SRCS:.c=.o)

KERNEL_SRCS = kernel/main.c
KERNEL_OBJS = $(KERNEL_SRCS:.c=.o)

OBJS = $(BOOT_OBJS) $(CONSOLE_OBJS) $(KERNEL_OBJS)

LINKER_SCRIPT = arch/x86/linker.ld

$(KERNEL): $(OBJS) $(LINKER_SCRIPT)
	$(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $(OBJS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	$(RM) -f $(OBJS) $(KERNEL)

.PHONY: clean
